package xyj.sparrow.scheduler.cron.thread;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * 调度线程池
 */
@Slf4j
@Component
public class SchedulingThreadPool {
    private static ExecutorService executorService;

    @PostConstruct
    private void init() {
        //初始化 调度线程池
        log.info("SchedulingThreadPool is init...");
        executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
    }

    /**
     * @param runnable
     */
    public void execute(Runnable runnable) {
        executorService.execute(runnable);
    }
}
